from pynput import keyboard,mouse
import threading,queue
def on_click(x,y, button, pressed): 
    return
ctrl_pressed =False
alt_pressed =False

is_v =False
is_h =False

start_pos = (0,0)
def on_v():
    print('on v')
    global is_v,is_h,start_pos
    if is_v:
        is_v = is_h =False
    else:
        is_v = True
        is_h =False
        start_pos = mouse.Controller().position

def on_h():
    print('on h')
    global is_v,is_h,start_pos
    if is_h:
        is_h = is_v = False
    else:
        is_v = False
        is_h = True
        start_pos = mouse.Controller().position


q = queue.Queue(1)

def do_move():
    while True:
        x,y = q.get()
        # print('get',x,y)
        mouse.Controller().move(x,y)
t = threading.Thread(target=do_move)
t.daemon = True
t.start()

def on_move(x,y):
    # print(x,y)
    try:
        if is_v and x!=start_pos[0]:
            # print('move',start_pos[0]-x,0)
            q.put((start_pos[0]-x,0),False)
        if is_h and y!=start_pos[1]:
            q.put((0,start_pos[1]-y),False)
            # print('move',0,start_pos[1]-y)
    except:
        pass
    
import time
def on_release(key):    
    global ctrl_pressed,alt_pressed
    x = str(key)
    # print('r',x)
    if x=='Key.ctrl_l':
        ctrl_pressed = False
    if x=='Key.alt_gr':
        alt_pressed =False
def on_press(key):    
    global ctrl_pressed,alt_pressed
    x = str(key)
    # print('p',x)
    if x=='Key.ctrl_l':
        ctrl_pressed = True
    if x=='Key.alt_gr':
        alt_pressed =True
    if ctrl_pressed and alt_pressed and x=='<86>':
        on_v()
    if ctrl_pressed and alt_pressed and x=='<72>':
        on_h()
listener = keyboard.Listener(
    on_press=on_press,
    on_release=on_release
)   
listener.start()
def testa():    
    mouse_listener = mouse.Listener(on_click=on_click,on_move=on_move)
    mouse_listener.start()
    mouse_listener.join()
testa()